﻿
//@note 端口号
var port = 9000 ;

//@note 全局变量定义
global.viewUrl = __dirname + '//views' ;

var express = require('express') ;
var app = express() ;

//@note 静态文件
app.use('/public',express.static(__dirname+'/public')) ;

var setParam = function( app , list ){
	var defConf = {
		url : (new Date()).getTime() + '.html' ,
		callback : function( req , res ){
			console.log('no callback') ;
		} ,
		method : 'get'
	} ;
	var listConf = [] ;

	if( typeof(list) !== 'object' || !list.length ){
		return [];
	}
	for( var i = 0 ; i < list.length ; i++ ){
		var conf = {
			method : list[i].method || defConf.method ,
			url : list[i].url || defConf.url ,
			callback : list[i].callback || defConf.callback
		} ;
		listConf.push(conf) ;
		app[conf.method]( conf.url ,conf.callback ) ;
	}
	return listConf ;
} ;
//@note 页面
var router = require('./node/url/index.js') ;
var routerList = setParam( app , router ) ;

//@note 文档
var doc = require('./node/doc/index.js') ;
var docList = setParam( app , doc ) ;

//@note 例子
var exam = require('./node/exam/index.js') ;
var examList = setParam( app , exam ) ;

var server = app.listen(port,function(){

	console.log( 'Listening on port %d' , server.address().port ) ;

	var writeLog = function( type , list ){
		if( list.length > 0 ){
			console.log('\n====='+ type +'=====') ;
			for( var i = 0 ; i < list.length ; i++ ){
				console.log(  list[i].url + ' can be access , method : ' + list[i].method ) ;
			}
			console.log('==========') ;
		}
	} ;

	//@note 页面log
	writeLog('url',routerList) ;

	//@note doc log
	writeLog('doc',docList) ;

	//@note exam log
	writeLog('exam',examList) ;

}) ;